package com.xsjl.search.service;


import com.xsjl.common.utils.IdWorker;
import com.xsjl.search.dao.ArticleSearchDao;
import com.xsjl.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ArticleSearchService {
    @Autowired
    private ArticleSearchDao searchDao;
    @Autowired
    private IdWorker idWorker;

    public void save(Article article) {
        article.setId(idWorker.nextId() + "");
        searchDao.save(article);
    }

    public Page<Article> findByTitleLike(String keywords, int page, int size) {
        Pageable pageable = PageRequest.of(page - 1, size);
        return searchDao.findByTitleOrContentLike(keywords, keywords, pageable);
    }
}
